package test;

import java.util.Random;

/**
 * 属性：血量、姓名
 * 动作：攻击另外一个角色
 */
public class Role {

    // 属性
    private String name;
    private int blood;

    public Role() {
    }

    public Role(String name, int blood) {
        this.name = name;
        this.blood = blood;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getBlood() {
        return blood;
    }

    public void setBlood(int blood) {
        this.blood = blood;
    }

    // 动作
    public void attack(Role role) {

        // 随机攻击的血量
        int hurt = new Random().nextInt(20) + 1;
        int remainBlood = role.getBlood() - hurt;
        remainBlood = remainBlood < 0 ? 0 : remainBlood;
        role.setBlood(remainBlood);
        System.out.println(this.name + "攻击了" + role.name + "造成了"+hurt+"点伤害," + role.name + "剩余血量：" + role.getBlood());
    }

}
